<?php
/*
	插件概览
*/
global $_RQ,$_AR;
$merchid=$this->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$setting = $this->plugin_setting('setting');
if($_RQ['op']=='edit'){
	$item=pdo_get('core_account_wxapp',array('plugin_key'=>$merchid,'plugin_name'=>'jy_merch_shop','uniacid'=>$_SESSION['uniacid']));
	$return['status']=array('1'=>'开启','0'=>'关闭');
	$return['post']=$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['appid']){
		exi('小程序appid必填','error');
	}
	if(!$postdata['appsecret']){
		exi('小程序appsecret必填！','error');
	}
	if(!$postdata['oldid']){
		exi('小程序原始ID必填！','error');
	}
	$merch=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
	if($postdata){
		$data =array(
			'title'=>trim($merch['merchname']),
			'logo'=>trim($merch['logo']),
			'oldid'=>trim($postdata['oldid']),
			'appid'=>trim($postdata['appid']),
			'appsecret'=>$postdata['appsecret'],
			'type'=>2,
		);
		if($postdata['id']){
			pdo_update('core_account_wxapp',$data,array('uniacid'=>$_SESSION['uniacid'],'plugin_key'=>$merchid,'plugin_name'=>'jy_merch_shop'));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['plugin_key']=$merchid;
			$data['plugin_name']='jy_merch_shop';
			pdo_insert('core_account_wxapp',$data);
		}
	}
	exi('设置成功','','goback');
}